<template>

    <div id="aduser">
        <g-admin></g-admin>
        <h1>编辑留言板信息</h1>
        <el-table :data="tableData" border="true" style="width: 85%">
            <el-table-column prop="messageID" label="留言ID" width="150px"></el-table-column>
            <el-table-column prop="message" label="留言内容" width="150px"></el-table-column>
            <el-table-column label="用户名" prop="userName"></el-table-column>
            <el-table-column label="留言时间" prop="leaveTime"></el-table-column>
            <el-table-column label="操作" width="180px">
                <template slot-scope="scope">
                    <!-- 删除按钮 -->
                    <el-button >审核留言内容</el-button>
                    <el-button @click="deleteMessage(scope.$index)" type="danger" size="small">删除</el-button>
                    <el-button @click="edit(scope.row['userName'])" type="text" size="small">用户违规操作，扣除其信誉分</el-button>
                </template>
            </el-table-column>
        </el-table>

    </div>

</template>

<script>
    import axios from 'axios';
    import GAdmin from '../../components/gadmin/GAdmin';
    export default {
        components:{
            GAdmin
        },
        data() {
            return {
                tableData:[{
                    messageID: '',
                    message:'',
                    userName:'',
                    leaveTime:''
                }
                ]

            }
        },
        created() {

            this.request({
                url:'http://127.0.0.1:8080/message/findall'
            }).then(res=>{
                this.tableData = res.data;
            })




        },
        mounted(){
            document.querySelector('.tabbar').setAttribute('style','display:none');
            document.querySelector('.gfooter').setAttribute('style','display:none');
        },
        methods: {
            deleteMessage(index){
                let url='http://localhost:8080/message/removemessage';
                axios.post(url, this.tableData[index]).then(
                    res=>{
                        alert("移除成功！");
                        location.reload(true);
                        console.log(res.data);
                    }).catch(err=>{
                        console.log(err);
                    }
                )
            },
            edit(userName){
                this.$router.push({
                    path:'/admin/admin/update',
                    query:{
                        userName:userName
                    }}).catch(error=>error)
            }

        }
    }
</script>

<style scoped>

    #aduser{
        width: 90%;
        margin-left: 10%;
        margin-top: 40px;
    }
</style>